package com.workcell.workdata.xthings.service.factory;

import com.alibaba.fastjson.JSONObject;
import com.workcell.workdata.xthings.constant.HardwareTypeEnum;
import com.workcell.workdata.xthings.dto.CodeChainnumVo;
import com.workcell.workdata.xthings.entity.CodeChainnum;
import com.workcell.workdata.xthings.service.impl.CodeBeltScalesServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeCameraServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeFlowmeterServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeFreezerServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeHeatExchangersServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeLevelGaugeServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeNaturalGasServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodePowermeterServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeRotaryKilnServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeSerialDeviceServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeSmartTanksServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeSoundLightAlarmServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeTemperatureHumidityServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeTimeClockServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeTvBoxServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeUpperComputerServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeValveServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeVoiceSynthesisServiceImpl;
import com.workcell.workdata.xthings.service.impl.CodeWaterMeterServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 廖博文
 * @Date 2022/11/30 14:00
 * @Description 二维码基本快照信息工厂
 */
@Service
@RequiredArgsConstructor
public class CodeBaseFactory {

    private final CodeFlowmeterServiceImpl codeFlowmeterService;
    private final CodePowermeterServiceImpl codePowermeterService;
    private final CodeTvBoxServiceImpl codeTvBoxService;
    private final CodeTimeClockServiceImpl codeTimeClockService;
    private final CodeSerialDeviceServiceImpl codeSerialDeviceService;
    private final CodeCameraServiceImpl codeCameraService;
    private final CodeBeltScalesServiceImpl codeBeltScalesService;
    private final CodeTemperatureHumidityServiceImpl codeTemperatureHumiditySvc;
    private final CodeFreezerServiceImpl codeFreezerService;
    private final CodeHeatExchangersServiceImpl codeHeatExchangersService;
    private final CodeLevelGaugeServiceImpl codeLevelGaugeService;
    private final CodeValveServiceImpl codeValveService;
    private final CodeUpperComputerServiceImpl codeUpperComputerService;
    private final CodeNaturalGasServiceImpl codeNaturalGasService;
    private final CodeSmartTanksServiceImpl codeSmartTanksService;
    private final CodeRotaryKilnServiceImpl codeRotaryKilnService;
    private final CodeWaterMeterServiceImpl codeWaterMeterService;
    private final CodeVoiceSynthesisServiceImpl codeVoiceSynthesisService;
    private final CodeSoundLightAlarmServiceImpl codeSoundLightAlarmService;

    public Boolean updateHardwareStatus(String deviceNo, String manufacturerCode, String status, String hardwareType) {
        switch (HardwareTypeEnum.getByCode(hardwareType)) {
            case VALVE:
                return codeValveService.updateHardwareStatus(deviceNo, manufacturerCode, status);
            default:
                return false;
        }
    }

    /**
     * 保存二维码基本快照信息
     *
     * @param codeChainnum
     * @return
     */
    public Boolean saveCodeBaseInfo(CodeChainnum codeChainnum, CodeChainnumVo.SaveChainNumVo saveChainNumVo) {
        switch (HardwareTypeEnum.getByCode(codeChainnum.getHardwareType())) {
            case FLOW_METER:
                return codeFlowmeterService.saveCodeBaseInfo(codeChainnum);
            case POWER_METER:
                return codePowermeterService.saveCodeBaseInfo(codeChainnum, saveChainNumVo);
            case TV_BOX:
                return codeTvBoxService.saveCodeBaseInfo(codeChainnum);
            case SERIAL_DEVICE:
                return codeSerialDeviceService.saveCodeBaseInfo(codeChainnum, saveChainNumVo);
            case TIME_CLOCK:
                return codeTimeClockService.saveCodeBaseInfo(codeChainnum, saveChainNumVo);
            case CAMERA:
                return codeCameraService.saveCodeBaseInfo(codeChainnum);
            case BELT_SCALES:
                return codeBeltScalesService.saveCodeBaseInfo(codeChainnum);
            case TEMPERATURE_HUMIDITY:
                return codeTemperatureHumiditySvc.saveCodeBaseInfo(codeChainnum);
            case FREEZER:
                return codeFreezerService.saveCodeBaseInfo(codeChainnum);
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.saveCodeBaseInfo(codeChainnum);
            case LEVEL_GAUGE:
                return codeLevelGaugeService.saveCodeBaseInfo(codeChainnum, saveChainNumVo);
            case VALVE:
                return codeValveService.saveCodeBaseInfo(codeChainnum);
            case NATURAL_GAS:
                return codeNaturalGasService.saveCodeBaseInfo(codeChainnum, saveChainNumVo);
            case UPPER_COMPUTER:
                return codeUpperComputerService.saveCodeBaseInfo(codeChainnum);
            case SMART_TANKS:
                return codeSmartTanksService.saveCodeBaseInfo(codeChainnum);
            case ROTARY_KILN:
                return codeRotaryKilnService.saveCodeBaseInfo(codeChainnum);
            case WATER_METER:
                return codeWaterMeterService.saveCodeBaseInfo(codeChainnum);
            case VOICE_SYNTHESIS:
                return codeVoiceSynthesisService.saveCodeBaseInfo(codeChainnum);
            case SOUND_LIGHT_ALARM:
                return codeSoundLightAlarmService.saveCodeBaseInfo(codeChainnum);
            default:
                return false;
        }
    }

    /**
     * 删除二维码基本快照信息
     *
     * @param codeId
     * @param type
     * @return
     */
    public Boolean removeCodeById(String codeId, String type) {
        switch (HardwareTypeEnum.getByCode(type)) {
            case FLOW_METER:
                return codeFlowmeterService.removeById(codeId);
            case POWER_METER:
                return codePowermeterService.removeById(codeId);
            case TV_BOX:
                return codeTvBoxService.removeById(codeId);
            case TIME_CLOCK:
                return codeTimeClockService.removeById(codeId);
            case SERIAL_DEVICE:
                return codeSerialDeviceService.removeById(codeId);
            case CAMERA:
                return codeCameraService.removeById(codeId);
            case BELT_SCALES:
                return codeBeltScalesService.removeById(codeId);
            case TEMPERATURE_HUMIDITY:
                return codeTemperatureHumiditySvc.removeById(codeId);
            case FREEZER:
                return codeFreezerService.removeById(codeId);
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.removeById(codeId);
            case LEVEL_GAUGE:
                return codeLevelGaugeService.removeById(codeId);
            case VALVE:
                return codeValveService.removeById(codeId);
            case NATURAL_GAS:
                return codeNaturalGasService.removeById(codeId);
            case UPPER_COMPUTER:
                return codeUpperComputerService.removeById(codeId);
            case SMART_TANKS:
                return codeSmartTanksService.removeById(codeId);
            case ROTARY_KILN:
                return codeRotaryKilnService.removeById(codeId);
            case WATER_METER:
                return codeWaterMeterService.removeById(codeId);
            case VOICE_SYNTHESIS:
                return codeVoiceSynthesisService.removeById(codeId);
            case SOUND_LIGHT_ALARM:
                return codeSoundLightAlarmService.removeById(codeId);
            default:
                return false;
        }
    }

    /**
     * 获取硬件清单
     *
     * @return
     */
    public List<JSONObject> getHardwareList(String type) {
        switch (HardwareTypeEnum.getByCode(type)) {
            case FLOW_METER:
                return codeFlowmeterService.getHardwareList();
            case POWER_METER:
                return codePowermeterService.getHardwareList();
            case TV_BOX:
                return codeTvBoxService.getHardwareList();
            case TIME_CLOCK:
                return codeTimeClockService.getHardwareList();
            case SERIAL_DEVICE:
                return codeSerialDeviceService.getHardwareList();
            case CAMERA:
                return codeCameraService.getHardwareList();
            case BELT_SCALES:
                return codeBeltScalesService.getHardwareList();
            case TEMPERATURE_HUMIDITY:
                return codeTemperatureHumiditySvc.getHardwareList();
            case FREEZER:
                return codeFreezerService.getHardwareList();
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.getHardwareList();
            case LEVEL_GAUGE:
                return codeLevelGaugeService.getHardwareList();
            case VALVE:
                return codeValveService.getHardwareList();
            case NATURAL_GAS:
                return codeNaturalGasService.getHardwareList();
            case UPPER_COMPUTER:
                return codeUpperComputerService.getHardwareList();
            case SMART_TANKS:
                return codeSmartTanksService.getHardwareList();
            case ROTARY_KILN:
                return codeRotaryKilnService.getHardwareList();
            case WATER_METER:
                return codeWaterMeterService.getHardwareList();
            case VOICE_SYNTHESIS:
                return codeVoiceSynthesisService.getHardwareList();
            case SOUND_LIGHT_ALARM:
                return codeSoundLightAlarmService.getHardwareList();
            default:
                return new ArrayList<>();
        }
    }

    /**
     * 获取硬件基本参数信息
     *
     * @return
     */
    public Object getHardwareBase(String baseIds, String type) {
        switch (HardwareTypeEnum.getByCode(type)) {
            case FLOW_METER:
                return codeFlowmeterService.getHardwareBase(baseIds);
            case POWER_METER:
                return codePowermeterService.getHardwareBase(baseIds);
            case TV_BOX:
                return codeTvBoxService.getHardwareBase(baseIds);
            case TIME_CLOCK:
                return codeTimeClockService.getHardwareBase(baseIds);
            case SERIAL_DEVICE:
                return codeSerialDeviceService.getHardwareBase(baseIds);
            case CAMERA:
                return codeCameraService.getHardwareBase(baseIds);
            case BELT_SCALES:
                return codeBeltScalesService.getHardwareBase(baseIds);
            case TEMPERATURE_HUMIDITY:
                return codeTemperatureHumiditySvc.getHardwareBase(baseIds);
            case FREEZER:
                return codeFreezerService.getHardwareBase(baseIds);
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.getHardwareBase(baseIds);
            case LEVEL_GAUGE:
                return codeLevelGaugeService.getHardwareBase(baseIds);
            case VALVE:
                return codeValveService.getHardwareBase(baseIds);
            case NATURAL_GAS:
                return codeNaturalGasService.getHardwareBase(baseIds);
            case UPPER_COMPUTER:
                return codeUpperComputerService.getHardwareBase(baseIds);
            case SMART_TANKS:
                return codeSmartTanksService.getHardwareBase(baseIds);
            case ROTARY_KILN:
                return codeRotaryKilnService.getHardwareBase(baseIds);
            case WATER_METER:
                return codeWaterMeterService.getHardwareBase(baseIds);
            case VOICE_SYNTHESIS:
                return codeVoiceSynthesisService.getHardwareBase(baseIds);
            case SOUND_LIGHT_ALARM:
                return codeSoundLightAlarmService.getHardwareBase(baseIds);
            default:
                return new ArrayList<>();
        }

    }

    /**
     * 查询硬件快照信息
     *
     * @return
     */
    public Object getHardwareInfo(String codeId, String type) {
        switch (HardwareTypeEnum.getByCode(type)) {
            case FLOW_METER:
                return codeFlowmeterService.getHardwareInfo(codeId);
            case POWER_METER:
                return codePowermeterService.getHardwareInfo(codeId);
            case TV_BOX:
                return codeTvBoxService.getHardwareInfo(codeId);
            case TIME_CLOCK:
                return codeTimeClockService.getHardwareInfo(codeId);
            case SERIAL_DEVICE:
                return codeSerialDeviceService.getHardwareBase(codeId);
            case CAMERA:
                return codeCameraService.getHardwareInfo(codeId);
            case BELT_SCALES:
                return codeBeltScalesService.getHardwareInfo(codeId);
            case TEMPERATURE_HUMIDITY:
                return codeTemperatureHumiditySvc.getHardwareInfo(codeId);
            case FREEZER:
                return codeFreezerService.getHardwareInfo(codeId);
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.getHardwareInfo(codeId);
            case LEVEL_GAUGE:
                return codeLevelGaugeService.getHardwareInfo(codeId);
            case VALVE:
                return codeValveService.getHardwareInfo(codeId);
            case NATURAL_GAS:
                return codeNaturalGasService.getHardwareInfo(codeId);
            case UPPER_COMPUTER:
                return codeUpperComputerService.getHardwareInfo(codeId);
            case SMART_TANKS:
                return codeSmartTanksService.getHardwareInfo(codeId);
            case ROTARY_KILN:
                return codeRotaryKilnService.getHardwareInfo(codeId);
            case WATER_METER:
                return codeWaterMeterService.getHardwareInfo(codeId);
            case VOICE_SYNTHESIS:
                return codeVoiceSynthesisService.getHardwareInfo(codeId);
            case SOUND_LIGHT_ALARM:
                return codeSoundLightAlarmService.getHardwareInfo(codeId);
            default:
                return null;
        }
    }

    public Object getHardwareBaseOpen(String deviceNo, String hardwareType) {
        switch (HardwareTypeEnum.getByCode(hardwareType)) {
            case FREEZER:
                return codeFreezerService.getHardwareBaseOpen(deviceNo);
            case HEAT_EXCHANGERS:
                return codeHeatExchangersService.getHardwareBaseOpen(deviceNo);
            case VALVE:
                return codeValveService.getHardwareBaseOpen(deviceNo);
            case UPPER_COMPUTER:
                return codeUpperComputerService.getHardwareBaseOpen(deviceNo);
            case SMART_TANKS:
                return codeSmartTanksService.getHardwareBaseOpen(deviceNo);
            default:
                return null;
        }
    }
}
